package team.fivez.defaultmanage.dao.Impl;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import team.fivez.defaultmanage.dao.IndustryInfoDao;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class IndustryInfoDaoImpl implements IndustryInfoDao {

    @Resource
    private JdbcTemplate jdbcTemplate;


    @Override
    public void insertInfoToDefault(String industry, String year) {
        String sql="insert into industry_default values(?,?)";
        jdbcTemplate.update(sql,industry,year);
    }

    @Override
    public List<String> getYearListFromDefault() {
        String sql="select distinct year from industry_default";
        return jdbcTemplate.queryForList(sql, String.class);
    }

    @Override
    public List<String> getIndustryListFromDefault() {
        String sql="select distinct industry from industry_default";
        return jdbcTemplate.queryForList(sql, String.class);
    }

    @Override
    public Integer getCountByIndustryAndYearFromDefault(String industry, String year) {
        String sql="select count(*) from industry_default where industry=? and year=?";
        return jdbcTemplate.queryForObject(sql, Integer.class, industry, year);

    }

    @Override
    public void insertInfoToRedo(String industry, String year) {
        String sql="insert into industry_redo values(?,?)";
        jdbcTemplate.update(sql,industry,year);
    }

    @Override
    public List<String> getYearListFromRedo() {
        String sql="select distinct year from industry_redo";
        return jdbcTemplate.queryForList(sql, String.class);
    }

    @Override
    public List<String> getIndustryListFromRedo() {
        String sql="select distinct industry from industry_redo";
        return jdbcTemplate.queryForList(sql, String.class);
    }

    @Override
    public Integer getCountByIndustryAndYearFromRedo(String industry, String year) {
        String sql="select count(*) from industry_redo where industry=? and year=?";
        return jdbcTemplate.queryForObject(sql, Integer.class, industry, year);
    }

    @Override
    public void deleteAllDefault() {
        String sql="delete from industry_default";
        jdbcTemplate.update(sql);
    }

    @Override
    public void deleteAllRedo() {
        String sql="delete from industry_redo";
        jdbcTemplate.update(sql);
    }
}
